﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;

namespace FileSystemItemSorter
{
    class FileSystemItem
    {
        public String ShortName { get; set; }
        public String LongName { get; set; }
        public String DisplayName
        {
            get
            {
                if (String.IsNullOrEmpty(LongName))
                {
                    return Encoding.Default.GetString(Convert.FromBase64String(ShortName));
                }
                else
                {
                    return LongName;
                }
            }
        }
        public Int32 Order { get; set; }
        public Boolean IsFolder { get; set; }
        public String ImageType { get; set; }

        public FileSystemItem(XmlElement element)
        {
            ShortName = element.SelectSingleNode("short_name").InnerText;
            XmlNode longNameNode = element.SelectSingleNode("long_name");
            if (longNameNode != null)
            {
                LongName = longNameNode.InnerText;
            }
            if ("directory".Equals(element.Name))
            {
                IsFolder = true;
                ImageType = "folder";
            }
            else if ("file".Equals(element.Name))
            {
                IsFolder = false;
                ImageType = "file";
                if (ShortName.ToUpper().EndsWith(".MP3")) ImageType = "mp3";
            }
        }
    }
}
